package com.leilei.serviceProject.domain.strategy.repository;

import com.leilei.serviceProject.domain.strategy.model.entity.StrategyAwardEntity;
import com.leilei.serviceProject.domain.strategy.model.entity.StrategyEntity;
import com.leilei.serviceProject.domain.strategy.model.entity.StrategyRuleEntity;
import com.leilei.serviceProject.domain.strategy.model.valobj.RuleTreeVo;
import com.leilei.serviceProject.domain.strategy.model.valobj.StrategyAwardCountSurplusVo;
import com.leilei.serviceProject.domain.strategy.model.valobj.StrategyAwardRuleModelVo;

import java.util.List;
import java.util.Map;

/**
 * @author yanglei
 * @description 策略服务仓储接口
 * @create 2024/10/15 15:12
 */
public interface IStrategyRepository {
    List<StrategyAwardEntity> queryStrategyAwardList(Long strategyId);

    void restoreStrategyAwardRateSearchTable(String strategyId, Integer shuffleStrategyAwardRateSearchTableSize, Map<Integer, Integer> shuffleStrategyAwardRateSearchTable);

    int queryRateRange(Long strategyId);

    int queryRateRange(String key);

    Integer getStrategyAwardRateSearchTable(String cacheKey, int rateKey);

    StrategyEntity queryStrategyEntityByStrategyId(Long strategyId);

    StrategyRuleEntity queryStrategyRuleEntity(Long strategyId, String ruleWeight);

    String queryStrategyRuleEntity(Long strategyId, Integer awardId, String ruleModel);

    StrategyAwardRuleModelVo queryStrategyAwardRuleModelsEntity(Long strategyId, Integer awardId);

    RuleTreeVo queryRuleTreeVoByTreeId(String ruleTreeId);

    /**
     * decr方式扣减
     * @param cacheKey 缓存键
     * @return 扣减结果
     */
    Boolean awardStockDeduction(String cacheKey);

    /**
     * 奖品库存消费发送至延迟队列
     * @param strategyAwardCountSurplusVo 发送至延迟队列值对象
     */
    void awardStockConsumeSendQueue(StrategyAwardCountSurplusVo strategyAwardCountSurplusVo);

    /**
     * 获取奖品库存消费队列
     * @return 消费队列数据
     */
    StrategyAwardCountSurplusVo takeQueueValue() throws InterruptedException;
    /**
     * 更新策略奖品库存
     * @param strategyId 策略id
     * @param awardId    奖品id
     */
    void updateStrategyAwardStock(Long strategyId, Integer awardId);
    void cacheStrategyAwardCount(String cacheKey, Integer awardCount);
}
